<!DOCTYPE html>
<html lang="zh">
<head>
    <meta charset="UTF-8">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>Document</title>
    <script src="https://cdn.jsdelivr.net/npm/vue/dist/vue.js"></script>
</head>
<body>
    <div id="app" style="border: 1px solid #ddd; width: 300px; padding: 8px;">
        <h1>简单计算器</h1>
        数值A：<input type="number" v-on:input = "changeContent1"><br>  <!-- 这里还可以用v-model进行双向绑定 -->
        数值B：<input type="number" v-on:input = "changeContent2" v-on:keyup.enter = "calculate"><br>
        <button v-on:click = "calculate">计算</button><br>
        <span>计算结果：{{ result }}</span>
    </div>
    


    <script>
        var vm = new Vue({
            el: "#app",
            data: {
                A: "",
                B: "",
                result: ""
            },
            methods: {
                changeContent1: function(event){
                    this.A = event.target.value;
                },
                changeContent2: function(event){
                    this.B = event.target.value;
                },
                calculate: function(){
                    this.result = parseInt(this.A) + parseInt(this.B);
                }
            }
        })
    </script>
</body>
</html>